package top.jiangqiang.qianyi.common.storage.config;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.dromara.hutool.core.text.StrUtil;
import top.jiangqiang.qianyi.common.constants.http.HttpProtocol;
import top.jiangqiang.qianyi.common.storage.base.BaseStorageConfig;

import java.util.Objects;

/**
 * @Date 2024/7/5 下午4:48
 * @Author Jiangqiang
 */
@Data
public class LocalStorageConfig extends BaseStorageConfig {
    /**
     * 文件上传路径
     */
    private String uploadPath;

    /**
     * 文件最终访问链接使用的协议，例如：HTTPS，如果不配置将使用当前接口请求采用的协议
     */
    @Schema(description = "文件最终访问链接使用的协议")
    private HttpProtocol accessProtocol;

    /**
     * 域名，如果不配置，使用调用上传文件接口时采用的IP和端口号
     */
    @Schema(description = "域名")
    private String domain;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        LocalStorageConfig that = (LocalStorageConfig) o;
        return Objects.equals(uploadPath, that.uploadPath) && accessProtocol == that.accessProtocol && Objects.equals(domain, that.domain);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), uploadPath, accessProtocol, domain);
    }

    @Override
    public String uniqueStr() {
        return StrUtil.concat(true, getName(), uploadPath);
    }
}
